#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"
void test1()
{
	Stack ps;
	StackInit(&ps);
	StackPush(&ps, 1);
	StackPush(&ps, 2);
	StackPush(&ps, 3);
	StackPush(&ps, 4);
	StackPop(&ps);
	StackPop(&ps);
	printf("%d\n",StackSize(&ps));
}


bool isValid(char* s) {
    Stack st;
    StackInit(&st);
    while (*s)
    {
        if (*s == '(' || *s == '[' || *s == '{')
        {
            StackPush(&st, *s);
            s++;
        }
        else
        {
            if (StackEmpty(&st))
            {
                return false;
                StackDestroy(&st);
            }
            char top = StackTop(&st);
            StackPop(&st);
            if (top == '{' && *s != '}' ||
                top == '[' && *s != ']' ||
                top == '(' && *s != ')')
            {
                StackDestroy(&st);
                return false;
            }
            else
            {
                s++;
            }
        }
    }
    bool ret = StackEmpty(&st);
    StackDestroy(&st);
    return ret;
}

typedef struct {
    Stack Emp;
    Stack unEmp;
} MyQueue;


MyQueue* myQueueCreate() {
    MyQueue* obj = (MyQueue*)malloc(sizeof(MyQueue));
    StackInit(&obj->Emp);
    StackInit(&obj->unEmp);
    return obj;
}

void myQueuePush(MyQueue* obj, int x) {
    StackPush(&obj->unEmp, x);
}

int myQueuePop(MyQueue* obj) {
    while (!StackEmpty(&obj->unEmp))
    {
        int tmp = StackTop(&obj->unEmp);
        StackPush(&obj->Emp, tmp);
        StackPop(&obj->unEmp);
    }
    int top = StackTop(&obj->Emp);
    StackPop(&obj->Emp);
    while (!StackEmpty(&obj->Emp))
    {
        int tmp = StackTop(&obj->Emp);
        StackPush(&obj->unEmp, tmp);
        StackPop(&obj->Emp);
    }
    return top;
}

int myQueuePeek(MyQueue* obj) {
    while (!StackEmpty(&obj->unEmp))
    {
        int tmp = StackTop(&obj->unEmp);
        StackPush(&obj->Emp, tmp);
        StackPop(&obj->unEmp);
    }
    int top = StackTop(&obj->Emp);
    while (!StackEmpty(&obj->Emp))
    {
        int tmp = StackTop(&obj->Emp);
        StackPush(&obj->unEmp, tmp);
        StackPop(&obj->Emp);
    }
    return top;
}

bool myQueueEmpty(MyQueue* obj) {
    return StackEmpty(&obj->unEmp) && StackEmpty(&obj->Emp);
}

void myQueueFree(MyQueue* obj) {
    StackDestroy(&obj->Emp);
    StackDestroy(&obj->unEmp);
    free(obj);
}


void TestMyStack()
{
    MyQueue* obj=myQueueCreate();
    myQueuePush(obj, 1);
    myQueuePush(obj, 2);
    int ret1=myQueuePeek(obj);
    myQueuePush(obj, 3);
    int ret2 = myQueuePeek(obj);
}

int main()
{
	//test1();
    //char str[10] = "({{{{}}}))";
    //isValid(str);
    TestMyStack();
}

